<template>
    <div class="container">
        <div class="title">
            <span>修改</span>
            <span class="back" @click="back">
        <i class="iconfont icon-fanhui"></i> 返回
      </span>
        </div>
        <el-divider></el-divider>
        <el-form label-width="80px">
            <div class="wrap">
                <el-form-item label="店面" prop="store_id">
                    <el-select v-model="store_id" clearable filterable placeholder="请选择店面">
                        <el-option
                                v-for="item in storeData"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="分组名称" prop="name">
                    <el-input
                            size="medium"
                            v-model="name"
                            placeholder="请填写分组名称"
                    ></el-input>
                </el-form-item>
                <el-form-item label="备注" prop="remarks">
                    <el-input
                            size="medium"
                            v-model="remarks"
                            placeholder="请填写备注"
                    ></el-input>
                </el-form-item>
                <el-form-item label="简介" prop="desc">
                    <el-input
                            size="medium"
                            v-model="desc"
                            placeholder="请填写简介"
                    ></el-input>
                </el-form-item>
                <el-form-item class="submit">
                    <el-button type="primary" @click="updateValue()">保 存</el-button>
                </el-form-item>
            </div>
        </el-form>
    </div>
</template>

<script>
import Store from '@/models/store'
import StoreGroup from '@/models/store-group'

export default {
  props: {
    StoreGroupId: {
      type: Number,
    },
  },
  data() {
    return {
      storeData: [],
      name: '',
      desc: '',
      remarks: '',
      store_id: '',
    }
  },
  mounted() {
    this.getStoreAll()
    this.getInfo()
  },
  methods: {
    async getStoreAll() {
      this.storeData = await Store.getStoreAll()
    },
    async getInfo() {
      const info = await StoreGroup.getStoreGroupInfo(this.StoreGroupId)
      this.name = info.name
      this.remarks = info.remarks
      this.desc = info.desc
      this.store_id = info.store_id
    },
    back() {
      this.$emit('editClose')
    },
    async updateValue() {
      const info = {
        id: this.StoreGroupId,
        name: this.name,
        remarks: this.remarks,
        desc: this.desc,
        store_id: this.store_id,
      }
      const res = await StoreGroup.updateStoreGroup(info)
      if (res.error_code === 0) {
        this.$message.success(`${res.msg}`)
        this.back()
      }
    },
  },
}
</script>

<style lang="scss" scoped>
    .el-divider--horizontal {
        margin: 0;
    }

    .container {
        .title {
            height: 59px;
            line-height: 59px;
            color: $parent-title-color;
            font-size: 16px;
            font-weight: 500;
            text-indent: 40px;

            .back {
                float: right;
                margin-right: 40px;
                cursor: pointer;
            }
        }

        .wrap {
            padding: 20px;
        }

        .submit {
            float: left;
        }
    }
</style>
